package com.erp.web.erp.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@Configuration
public class RedisConfig {
	@Value("${spring.redis.host}")
	private String host;
	@Value("${spring.redis.password}")
	private String password;
	@Value("${spring.redis.port}")
	private int port;
	@Value("${spring.redis.timeout}")
	private int timeout;
	@Value("${spring.redis.jedis.pool.max-idle}")
	private int maxIdle;
	@Value("${spring.redis.jedis.pool.max-active}")
	private int maxTotal;
	@Value("${spring.redis.jedis.pool.max-wait}")
	private long maxWaitMillis;
	
	@Bean
	public JedisPoolConfig getRedisConfig() {
		JedisPoolConfig poolConfig = new JedisPoolConfig();
		return poolConfig;
	}

	@Bean
	public JedisPool getJedisPool() {
		JedisPoolConfig config = getRedisConfig();
		config.setMaxIdle(maxIdle);
		config.setMaxTotal(maxTotal);
		config.setMaxWaitMillis(maxWaitMillis);
		JedisPool pool = new JedisPool(config, host, port, timeout);
		return pool;
	}
	@Bean
	public Jedis getJedis() {
		return getJedisPool().getResource();

	}
}
